package com.zitronella.course.osseventmanager.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;

import javax.servlet.http.HttpSession;

import com.zitronella.course.osseventmanager.service.PositionService;
import com.zitronella.course.osseventmanager.service.EventService;
import com.zitronella.course.osseventmanager.domain.Event;
import com.zitronella.course.osseventmanager.domain.EventUser;
import com.zitronella.course.osseventmanager.domain.Position;
import com.sun.deploy.net.HttpRequest;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Robin
 * Date: Mar 23, 2009
 * Time: 11:51:45 PM
 * To change this template use File | Settings | File Templates.
 */

@Controller
@RequestMapping("/myevents")
public class MyEventListController {

    private EventService eventService;

    @Autowired
    public void setEventService(EventService evService) {
        this.eventService = evService;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String prepareEventList(Model model, HttpSession session) {
        
        model.addAttribute("events", eventService.findEventByAdministratorEmail(getEventUser(session).getEmail()));
        System.out.println(eventService.findEventByAdministratorEmail(getEventUser(session).getEmail()).size());
        return "events";                
    }

   private EventUser getEventUser(HttpSession session) {
        EventUser testUser = new EventUser("robin@gmail.com","robin", "","");
        session.setAttribute("user",testUser);
        return (EventUser) session.getAttribute("user");
    }

}
